﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ReceiptTracker
{
    public partial class FormAddCategory : Form
    {
        private SQLiteDB db;
        public FormAddCategory(SQLiteDB db)
        {
            InitializeComponent();
            this.db = db;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            Regex rgx = new Regex(@"^[a-öA-Ö`\s]*$");
            if (!rgx.IsMatch(textBoxName.Text))
            {
                MessageBox.Show("Invalid characters in category name\nValid characters are a-ö, A-Ö and `", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                db.SQLCommand("INSERT INTO Categories (name) VALUES ('" + textBoxName.Text.Replace('\'', '`') + "');");
                this.DialogResult = DialogResult.OK; 
            }
        }
    }
}
